package cn.net.zj.scan.ui;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;


import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.net.zj.scan.R;

/**
 * Created by Huan on 2018/2/7.
 */

public class BaseActivity extends AppCompatActivity {

    ProgressDialog progressDialog;
    private InputMethodManager mInputMethodManager;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResId());
        ButterKnife.bind(this);
        init();
    }

    public void init() {
        //初始化一些公共方法
    }

    public void showProgress(String msg) {
        progressDialog = new ProgressDialog(this);
        progressDialog.setMessage(msg);
        progressDialog.setCancelable(false);
        progressDialog.show();

    }
    public void dismissProgress() {
        if (progressDialog!=null){
            progressDialog.dismiss();
        }else {
            Log.e("BaseActivity:","progressDialog is null");
        }
    }

    public void hideSoftkeyboard(){
        if (mInputMethodManager == null) {
            mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        }
        mInputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }

    protected int getLayoutResId() {
        return 0;
    }


    @OnClick(R.id.ll_left_back)
    public void back(View view){
        finish();
    }
}
